package lab03.test03;

import java.io.*;

/**3、	在某目录下创建一个文本文件test.txt，通过字节输出流向文件中写入“Beijing欢迎你！”，
 * 通过字节输入流读出文件中的内容并显示；如果在已有文件中再追加“我的学号是：你自己的学号”如何实现
 * Created by dell on 2017/11/16.
 */
public class Test {

    public static void main(String[] args) {
        String path="D:\\test.txt";
        File file=new File(path);

        FileOutputStream fileOutputStream=null;
        FileInputStream fileInputStream=null;
        FileWriter fileWriter  = null;


        try {
            try {
                fileOutputStream=new FileOutputStream(file);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            fileInputStream = new FileInputStream(path);
            fileOutputStream.write(new String("Beijing欢迎你!").getBytes());
            byte[] data = new byte[100];


            while ((fileInputStream.read(data)) != -1){
                String keyword;
                keyword = new String(data,"GBK");
                System.out.println(keyword);
            }

            fileWriter = new FileWriter(path,true);
            fileWriter.write("我的学号：1606101076");

        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileOutputStream.close();
                fileInputStream.close();
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


}

